var isIE = (document.all) ? true : false;
var getEvent = function(evt) {
	return evt ? evt : (window.event ? window.event : null);
};
var _x, _y, _cx, _cy;
var oDragObj;
function mouseDown(event) {
	e = getEvent(event);
	var srcElement = e.srcElement || e.target;
	oDragObj = srcElement;
	if (srcElement.id != "mainDiv"&& srcElement.id != "main") {
		var id = oDragObj.id;
		if (id == "mapDiv"||id=="mapImg"||id.indexOf("readRadius")!=-1||id.indexOf("read")!=-1) {
			oDragObj=getId("mapDiv");
			_x = parseInt(e.clientX);
			_y = parseInt(e.clientY);
			_cx = parseInt(oDragObj.style.left);
			_cy = parseInt(oDragObj.style.top);
			document.onmousemove = mouseMove;
			return false;
		}
	}
	return true;
}
function mouseMove(event) {
	e = getEvent(event);
	oDragObj.style.left = parseInt(_cx + e.clientX - _x) + "px";
	oDragObj.style.top = parseInt(_cy + e.clientY - _y) + "px";
	return true;
}
function mouseUp(event) {
	document.onmousemove = null;
	return true;
}
Number.prototype.NaN0 = function() {
	return isNaN(this) ? 0 : this;// 如果this为非数字返回0,否则返回数字
}
// 获取鼠标相对document的坐标
function getMouseCoord(evt) {
	if (evt.pageX && evt.pageY)
		return {
			x : evt.pageX,
			y : evt.pageY
		};
	return {
		x : evt.clientX + document.body.scrollLeft - document.body.clientLeft,
		y : evt.clientY + document.body.scrollTop - document.body.clientTop
	};
}
// 获取HTML元素相对document的坐标
function getPosition(ele) {
	var x = ele.offsetLeft
			+ (ele.curentStyle ? (parseInt(ele.curentStyle.borderLeftWidth)
					.NaN0()) : 0);
	var y = ele.offsetTop
			+ (ele.curentStyle ? (parentInt(ele.curentStyle.borderTopWidth)
					.NaN0()) : 0);
	while (ele.offsetParent) {
		ele = ele.offsetParent;
		x += ele.offsetLeft
				+ (ele.curentStyle ? (parseInt(ele.curentStyle.borderLeftWidth)
						.NaN0()) : 0);
		y += ele.offsetTop
				+ (ele.curentStyle ? (parentInt(ele.curentStyle.borderTopWidth)
						.NaN0()) : 0);
	}
	return {
		x : x,
		y : y
	};
}

// 获取鼠标相对与点击空件上的坐标
function getMouseOffset(target, event,minWidth, minHeight) {
	var elePosition = getPosition(target);
	var evn = getEvent(event);
	var mouseCoord = getMouseCoord(evn);
	var absoluteX = mouseCoord.x - elePosition.x;
	var absoluteY = mouseCoord.y - elePosition.y;
	var realX = parseInt(getId("mapImg").style.width) * (absoluteX / minWidth);
	var realY = parseInt(getId("mapImg").style.height) * (absoluteY / minHeight);
	var mainDivWidth = parseInt(getId('mainDiv').style.width);
	var mainDivHeight = parseInt(getId('mainDiv').style.height);
	getId("mapDiv").style.left = -parseInt(realX - mainDivWidth / 2) + "px";
	getId("mapDiv").style.top = -parseInt(realY - mainDivHeight / 2) + "px";
}
function scrollImage(id, speed) // 被缩放图象id与缩放速度
{
	var speed = speed ? speed : 1;
	var is_ff = navigator.userAgent.toLowerCase().indexOf('firefox');
	this.onload = function() {
		if (is_ff > 0)
			getId("mapImg").addEventListener("DOMMouseScroll", zoom, false);
		else
			getId("mapImg").onmousewheel = function(){initRealTimeInfo(event.wheelDelta)};
			for(var i=0;i<readList.length;i+=1){
				var readDiv =getId("read"+readList[i][0]);
				var readRaduis =getId("readRadius"+readList[i][0]);
				readRaduis.onmousewheel = function(){initRealTimeInfo(event.wheelDelta)};
				readDiv.onmousewheel = function(){initRealTimeInfo(event.wheelDelta)};
				readRaduis.onmousedown = mouseDown;
				readDiv.onmousedown = mouseDown;
				readRaduis.onmouseup = mouseUp;
				readDiv.onmouseup = mouseUp;
			}
			return false;
	}
}
var img = new scrollImage("mapImg", 1);
document.onmousedown = mouseDown;
document.onmouseup = mouseUp;

